<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="用户列表" width="800px">
    <!--表格渲染-->
    <el-table v-loading="loading" ref="userTable" :data="data.rtnList" size="small" style="width: 100%;" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="userAccount" label="用户账号"/>
      <el-table-column prop="userName" label="名称" width="150px" />
      <el-table-column prop="phone" label="电话" width="200px" />
      <el-table-column prop="email" label="邮件" width="200px" />
      <el-table-column label="用户状态" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.user_status" :key="item.id">
            <el-tag v-if="scope.row.userStatus.toString() === item.dictCode" :type="scope.row.userStatus === 'UNLOCK' ? '' : 'info'">{{ item.dictName }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="有效" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.enable_flag" :key="item.id">
            <el-tag v-if="scope.row.enableFlag.toString() === item.dictCode" :type="scope.row.enableFlag === 'Y' ? '' : 'info'">{{ item.dictName }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="createDate" label="创建日期" width="200px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <!--<el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>-->
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import initDict from '@/mixins/initDict'
import { findUserByCpyCodeUrl } from '@/api/orgSet'
import { parseTime } from '@/utils/index'
import { getUserInfo } from '@/utils/auth'

export default {
  mixins: [initData, initDict],
  props: {
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      loading: false,
      dialog: false,
      selectedRows: []
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    async initDataDict() {
      await this.getSyncDictByType('user_status')
      await this.getSyncDictByType('enable_flag')
    },
    async beforeInit() {
      this.url = findUserByCpyCodeUrl()
      if (!this.dicts.user_status) {
        await this.initDataDict()
      }
      this.paramBean.cpyCode = getUserInfo().cpyCode
      return true
    },
    handleSelectionChange(val) {
      this.selectedRows = val
    },
    doSubmit() {
      this.loading = true
      this.sup_this.doUserSelectCallback(this.selectedRows, this)
    },
    cancel() {
      this.dialog = false
    }
  }
}
</script>
